package com.test.daily.leetcode.y2021.m10.day1007;

/**
 * countSegments
 *
 * https://leetcode-cn.com/problems/number-of-segments-in-a-string/
 *
 * @author Tom on 2021/10/7
 */
public class Code01_CountSegments {
    public static void main(String[] args) {
        String s = "   22  ";
        System.out.println(countSegments(s));
    }
    public static int countSegments(String s) {
        if(s.length() == 0) return 0;
        char[] str = s.trim().toCharArray();
        if(str.length == 0) return 0;
        int count = 0;
        for (int i = 1; i < str.length - 1; i++) {
            if(str[i] == ' ' && str[i+1] != ' '){
                count++;
            }
        }
        return count + 1;
    }
}
